﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Wicresoft.EKA.Lib.WebApp
{
    public partial class Index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public SqlConnection GetConnection()
        {
            return new SqlConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|gongshangDB.mdb;");
        }

        public void dlDataBind(string sqlstr, string table, string dkf) 
        {
            int curpage = Convert.ToInt32(this.labPage.Text);
            PagedDataSource ps = new PagedDataSource();
            SqlConnection sqlconn = GetConnection();
            sqlconn.Open();
            SqlDataAdapter myAdapter = new SqlDataAdapter(sqlstr, sqlconn);
            DataSet ds = new DataSet();
            myAdapter.Fill(ds, table);
            ps.DataSource = ds.Tables[table].DefaultView;
            ps.AllowPaging = true;   //是否可以分页显示
            ps.PageSize = 5;   //显示的数量
            ps.CurrentPageIndex = curpage - 1;  //取得当前页的页码
            this.lnkbtnUp.Enabled = true;
            this.lnkbtnOne.Enabled = true;
            this.lnkbtnNext.Enabled = true;
            this.lnkbtnBack.Enabled = true;

            if (curpage == 1)
            {
                this.lnkbtnUp.Enabled = false;   //不显示第一页按钮
                this.lnkbtnOne.Enabled = false;   //不显示上一页按钮
            }
            if (curpage == ps.PageCount) 
            {
                this.lnkbtnNext.Enabled = false;  //不显示下一页按钮
                this.lnkbtnBack.Enabled = false;  //不显示最后一页按钮
            }
            this.labBackPage.Text = Convert.ToString(ps.PageCount);
            this.dlInfo.DataSource = ps;
            this.dlInfo.DataKeyField = dkf;
            this.dlInfo.DataBind();
        }

        public void dlInfoBind() 
        {
            if (ddlInfoType.Visible == false) 
            {
                string sqlstr = "select * from tb_Info where" + ddlSCondition.SelectedValue.Trim() + " '%" + txtSKWord.Text.Trim() + "%'";
                this.dlDataBind(sqlstr, "tb_table", "InfoID");
            }
        }


    }
}